package com.qf.domain;

import java.util.List;

public class PageBean<T> {
    //页码
    private int pageNum;
    //页大小
    private int pageSize;
    //总数据量
    private long totalSize;
    //总页数
    private int pageCount;
    //数据
    private List<T> data;
    //开始页
    private int startPage;
    //结束页
    private int endPage;

    public PageBean() {
    }

    public PageBean(int pageNum, int pageSize, long totalSize, List<T> data) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.data = data;
        //计算总页数
        this.pageCount = (int) (totalSize % pageSize == 0 ? totalSize / pageSize : totalSize / pageSize + 1);
        //1正常情况下
        this.startPage = this.pageNum - 4;
        this.endPage = this.pageNum + 5;
        //2当页面小于等于5
        if (this.pageNum <= 5) {
            this.startPage = 1;
            this.endPage = 10;
        }
        //3当页面大于总页码-5
        if (this.pageNum > this.pageCount - 5) {
            this.startPage = this.pageCount - 9;
            this.endPage = this.pageCount;
        }
        //4不足10页
        if (this.pageCount <= 10) {
            this.startPage = 1;
            this.endPage = this.pageCount;
        }

    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }


    @Override
    public String toString() {
        return "PageBean{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", totalSize=" + totalSize +
                ", pageCount=" + pageCount +
                ", data=" + data +
                ", startPage=" + startPage +
                ", endPage=" + endPage +
                '}';
    }
}
